#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

typedef struct{
    char *addr;
    int data;
}RoseInfo;

void *red_handle(void *arg){

        char input[10];

    while (1)
    {
        char code = *(char *)arg;
        fgets(input,sizeof(input),stdin);
        if(input[0] == code){

            RoseInfo *redinfo = malloc(sizeof(RoseInfo));
            redinfo->addr = "巴黎";
            redinfo->data = 19;
            printf("红玫瑰结束了她的旅程\n");
            // pthread_exit(NULL);
            return redinfo;
        }else
        {
            printf("红玫瑰的秘密:%s\n",input);
        }
        
    }
    
}
void *write_handle(void *arg){

        char input[10];

while (1)
    {
        char code = *(char *)arg;
        fgets(input,sizeof(input),stdin);
        if(input[0] == code){

            RoseInfo *writeinfo = malloc(sizeof(RoseInfo));
            writeinfo->addr = "纽约";
            writeinfo->data = 20;
            printf("白玫瑰结束了她的旅程\n");
            // pthread_exit(NULL);
            return writeinfo;
        }else
        {
            printf("白玫瑰的秘密:%s\n",input);
        }
        
    }
}

int main(int argc, char const *argv[])
{
    pthread_t red_pt,write_pt;

    char red_val = 'r';
    char write_val = 'w';


    pthread_create(&red_pt,NULL,red_handle,&red_val);
    pthread_create(&write_pt,NULL,write_handle,&write_val);

    RoseInfo *red_addr;
    RoseInfo *write_addr;
    pthread_join(red_pt,(void **)&red_addr);
    pthread_join(write_pt,(void **)&write_addr);
    printf("红玫瑰的结局她在%d号去了:%s\n",red_addr->data,red_addr->addr);
    printf("白玫瑰的结局她在%d号去了:%s\n",write_addr->data,write_addr->addr);

    return 0;
}
